<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>08_Promise的几个关键问题1</title>
</head>

<body>
  <!-- 
    1. 如何改变一个 Promise实例的状态?
        (1). 执行resolve(value): 如果当前是 pending就会变为 fulfilled
        (2). 执行reject(reason): 如果当前是 pending就会变为 rejected
        (3). 执行器函数(executor)抛出异常: 如果当前是 pending就会变为 rejected
  -->

  <script>
    // 演示: 执行器函数(executor)抛出异常
    const p = new Promise((resolve,reject) => {
      // console.log(a);     // 引擎抛异常
      throw 900;             // 编码抛异常
    });
    p.then(
      (value) => { console.log('成功了:', value) },
      (reason) => { console.log('失败了:', reason) }
    );
  </script>
</body>

</html>
